package models

import (
	"github.com/redis/go-redis/v9"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
)

var db *gorm.DB
var Redis *redis.Client

func init() {
	var err error
	dsn := "root:root@tcp(127.0.0.1:3306)/shang?charset=utf8mb4&parseTime=True&loc=Local"
	db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		log.Println("数据库链接失败")
	}
	err = db.AutoMigrate(new(User3), new(Goods3), new(Order3))
	if err != nil {
		log.Println("建表失败")
	}

	Redis = redis.NewClient(&redis.Options{
		Addr: "localhost:6379",
		DB:   0,
	})
}
